#pragma once

#include <Windows.h>

class CriticalSection
{
private:
	CRITICAL_SECTION m_critSection;

public:
	CriticalSection()  { ::InitializeCriticalSectionAndSpinCount(&m_critSection, 4000);}
	~CriticalSection() { ::DeleteCriticalSection(&m_critSection); }
	void lock() { ::EnterCriticalSection(&m_critSection); }
	void unlock() { ::LeaveCriticalSection(&m_critSection); }
private:
	CriticalSection(const CriticalSection&);
	CriticalSection& operator=(const CriticalSection&);
};


class CScopeLock
{
private:
	CriticalSection& m_lock;
public:
	explicit CScopeLock(CriticalSection& cslock):m_lock(cslock)
	{
		m_lock.lock();
	}

	~CScopeLock()
	{ 
		m_lock.unlock();
	}

private:
	CScopeLock(const CScopeLock&);
	CScopeLock& operator=(const CScopeLock&);
};